import * as types from '../types'
import  api from '../../fetch/api'

const state = {
    source:"web",
    version:"3.2.7",
	addressdata:[],//城市列表
	houseRent:'整套出租',
	roomRent:'单间出租',
	bedRental:'床位出租',
	mySessionUserinfo:JSON.parse(sessionStorage.getItem("userinfo")),//登录验证
	GetSpbillcreateipData:[]
}

const actions = {
    setOpenApp({ commit },_url) {
//      window.location="https://apis.zhudd.com/openApp.html"
        window.location=_url;//打开新链接
    },
    getCityInfo({commit}) {
		var ajaxSign = {
			"source": "web",
		};
		let ajaxData = api.getAES(ajaxSign);
		api.GetAddress(ajaxData)
		.then(res => {
			commit(types.PUBLIC_ADDRESS_DATA, res.result)
		})
	},
    getCityIP({commit}) {
		api.GetSpbill_create_ip()
		.then(res=>{
		commit(types.PUBLIC_GETSPBILL_CREATE_IP, res)
		})
	},
}

const getters = {
    source:state=>state.source,
    version:state=>state.version,
    addressdata:state=>state.addressdata,
    mySessionUserinfo:state=>state.mySessionUserinfo,
    GetSpbillcreateipData:state=>state.GetSpbillcreateipData,
    houseRent:state=>state.houseRent,
    roomRent:state=>state.roomRent,
    bedRental:state=>state.bedRental,
}


const mutations = {
	[types.PUBLIC_ADDRESS_DATA](state, res) {
		state.addressdata = res
	},
	[types.PUBLIC_GETSPBILL_CREATE_IP](state, res) {
		state.GetSpbillcreateipData = res
	},
}


export default {
    state,
    actions,
    getters,
    mutations
}